home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Just Call Me Internet
/
Just Call Me Internet.iso
/
prog
/
atari
/
c
/
zmdm
/
main.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-06-26
|
10KB
|
492 lines
/*
* Main Module
*
* Jwahar Bammi
* usenet: cwruecmp!bammi@decvax.UUCP
* csnet: bammi@cwru.edu
* arpa: bammi@cwru.edu
* CompuServe: 71515,155
*/
#include "zmdm.h"
#ifndef Vsync /* Atari forgot these in osbind.h */
#define Vsync() xbios(37)
#endif
#define esc 27
#define cr 0x0d
#define mvto(r,c) EscSeq('Y');Bconout(2,r+040);Bconout(2,c+040)
/* Global variable definitions, extern everywhere else */
int *aline_addr; /* Base addr of aline variables */
int hlines = 25; /* # of lines on screen */
int rez; /* current resolution */
int scolor = 0; /* current fg/bg screen color toggle */
long *ms_ptr; /* Pointer to my screen memory, aligned at
a 256 bytes boundary */
#ifndef MWC
long m_screen[8*1024+32]; /* My screen memory
32K bytes + 256 Bytes guard for alignement
In the worst case when we align we have to
go 255 bytes from &m_screen[0], hence the
256 Byte guard is required */
#else
#ifdef RECURSE
#ifdef BIGSTACK
long _stksize = 128L * 1024L;
#else
long _stksize = 16L * 1024L;
#endif
#else
long _stksize = 16384L;
#endif /* RECURSE */
long *m_screen; /* Presently Mark Willams will not allow
> 32K static structures */
extern unsigned char *bufr; /* Here for the same reason */
#endif /* MWC */
struct stat statbuf; /* Disk Transfer address for Find first etc */
int Baudrate; /* Current baud rate */
long drv_map; /* bit vector of valid drives */
/* Types */
/* Globals belonging to this module only */
IOREC save, /* the original Iorec is saved here for the duration of this
process */
*p; /* ptr returned by Iorec() */
char iobuf[IBUFSIZ]; /* My large Rs232 receive buffer */
int rs232 = 1, /* Ports */
console = 2;
int speed, /* rs232 setup parameters */
#ifdef FLOW_CTRL
flowctl = 1,
#else
flowctl = 0,
#endif
ucr = -1,
rsr = -1,
tsr = -1,
scr = -1;
/*
* SetIoBuf() - Save the systems Rs232 buffer and install my large
* Rs232 buffer.
*
*/
void SetIoBuf()
{
/* Get pointer to Rs232 input record */
p = (IOREC *)Iorec(0);
/* Save the info */
save.ibuf = p->ibuf;
save.ibufsiz = p->ibufsiz;
save.ibufhd = p->ibufhd;
save.ibuftl = p->ibuftl;
save.ibuflow = p->ibuflow;
save.ibufhi = p->ibufhi;
/* Install my buffer in its place */
p->ibuf = &iobuf[0];
p->ibufsiz = IBUFSIZ;
p->ibuflow = IBUFSIZ/4;
p->ibufhi = IBUFSIZ / 4 * 3;
p->ibufhd = p->ibuftl = 0;
}
/*
* ResetIoBuf() - Reset the Rs232 buffer to the saved (system's) buffer
*
*/
void ResetIoBuf()
{
p->ibuf = save.ibuf;
p->ibufsiz = save.ibufsiz;
p->ibuflow = save.ibuflow;
p->ibufhi = save.ibufhi;
p->ibufhd = save.ibufhd;
p->ibuftl = save.ibuftl;
}
/*
* setRs232() - set rs232 port configuration
*/
void setRs232 ()
{
char ch;
long conin;
Bconws("Baud rate: ");
EscSeq('p');
Bconws("0=19200 1=9600, 2=4800, 3=2400, 4=1200, 5=300\r\n");
EscSeq('q');
Bconout(2, '\t');
EscSeq('p');
Bconws("What speed==>");
EscSeq('q');
conin = Bconin(console); /* get speed */
if ((conin & 0x00FF0000L) == 0x00610000L)
{
his_screen();
ResetIoBuf();
finish();
}
ch = (char) (conin & 0x007f);
Bconout(2, ' ');
switch (ch)
{
case '0': /* 19200 */
speed = 0;
Bconws("19200");
Baudrate = 19200;
break;
case '1':
speed = 1; /* 9600 */
Bconws("9600");
Baudrate = 9600;
break;
case '2':
speed = 2; /* 4800 */
Bconws("4800");
Baudrate = 4800;
break;
case '3':
speed = 4; /* 2400 */
Bconws("2400");
Baudrate = 2400;
break;
case '4':
speed = 7; /* 1200 */
Bconws("1200");
Baudrate = 1200;
break;
case '5':
speed = 9; /* 300 */
Bconws("300");
Baudrate = 300;
break;
default:
speed = BAUD_DEFAULT;
Bconws(BAUD_STRING);
Baudrate = BAUD_RATE;
}
Bconws(" Baud\r\n");
/* Set new Baud rate */
/* Txoff(); */
Rsconf(speed, flowctl, ucr, rsr, tsr, scr);
Vsync(); Vsync();
/* Txon(); */
}
/*
* help() - display help info and menu
*/
void help ()
{
register long conin;
extern char *r_filename();
my_screen(); /* Switch to my screen memory */
EscSeq('v'); /* wrap at end of line */
EscSeq('E'); /* clear screen */
mvto(2,32);
EscSeq('p');
Bconws("ZMDM Version ");
Bconws(ZMDMVERSION);
EscSeq('q');
mvto(4,29);
Bconws("ST Enthusiasts @ CWRU\r\n\n");
/* Put up menu */
Bconws("\r\n\t");
EscSeq('p'); /* reverse video */
Bconws("Undo");
EscSeq('q'); /* quit reverse video */
Bconws(" to exit.\r\n");
Bconws("\t");
EscSeq('p'); /* reverse video */
Bconws("Help");
EscSeq('q'); /* quit reverse video */
Bconws(" for this message.\r\n");
Bconws("\t");
EscSeq('p'); /* reverse video */
Bconws("Escape");
EscSeq('q'); /* quit reverse video */
Bconws(" to send a break.\r\n");
Bconws("\t");
EscSeq('p'); /* reverse video */
Bconws("T or t");
EscSeq('q'); /* quit reverse video */
Bconws(" to do file transfers and local functions.\r\n");
if(rez == 2)
{
Bconws("\t");
EscSeq('p'); /* reverse video */
Bconws("H or h");
EscSeq('q'); /* quit reverse video */
Bconws(" for Hi Rez Toggle (25/50 Lines).\r\n");
}
Bconws("\t");
EscSeq('p'); /* reverse video */
Bconws("I or i");
EscSeq('q'); /* quit reverse video */
Bconws(" to Invert screen colors.\r\n");
Bconws("\t");
EscSeq('p'); /* reverse video */
Bconws("Return");
EscSeq('q'); /* quit reverse video */
Bconws(" to do nothing.\r\n");
Bconws("\t");
EscSeq('p'); /* reverse video */
Bconws("B or b");
EscSeq('q'); /* quit reverse video */
Bconws(" to set baud rate. Default is ");
EscSeq('p');
Bconws(BAUD_STRING);
Bconws(" Baud.\r\n\r\n");
EscSeq('q');
/* get response */
conin = Bconin(console);
if ((conin & 0x00FF0000L) == 0x00610000L)
{
/* He hit <UNDO> */
his_screen();
ResetIoBuf();
finish();
}
switch((int)(conin & 0x007f))
{
case 'B':
case 'b':
/* Set baud rate */
setRs232();
break;
case 'T':
case 't':
EscSeq('E'); /* clear screen */
/* Set no flow Control */
#ifdef FLOW_CTRL
Rsconf(-1,0,-1,-1,-1,-1);
Vsync(); Vsync();
#endif
/* Go do transfers */
transfer();
#ifdef FLOW_CTRL
/* Flow Control On */
/* Txoff(); */
Rsconf(-1,1,-1,-1,-1,-1);
Vsync(); Vsync();
/* Txon(); */
#endif
his_screen();
return;
case '\033':
/* Send a break */
sendbrk();
his_screen(); /* Don't wait for the key hit */
return;
case 'i':
case 'I':
/* Invert screen colors */
his_screen();
if(scolor == 0)
{
EscSeq('b'); /* Foreground color 0 */
Bconout(2, 0);
EscSeq('c'); /* Background color 1 */
Bconout(2, 1);
scolor = 1;
}
else
{
EscSeq('b'); /* Foreground color 1 */
Bconout(2, 1);
EscSeq('c'); /* Background color 0 */
Bconout(2, 0);
scolor = 0;
}
EscSeq('E'); /* Clear the screen */
return;
case 'h':
case 'H':
/* Hi rez 25/50 toggle */
if(rez == 2)
{
if(hlines == 25)
{
hlines = 50;
hi50();
}
else
{
hlines = 25;
hi25();
}
his_screen();
EscSeq('E'); /* clear screen */
return;
}
/* else fall Through */
default:
Bconws("No Change\r\n");
}
/* Wait for a key hit */
hit_key();
/* back to terminal screen */
his_screen();
}
main ()
{
register int c; /* rs232 input */
register int i;
register long conin;
extern int *aaddress(); /* Routine that returns base address of
* line A variables
*/
#ifdef MWC
extern char *lmalloc();
#endif
/* Set up Dta */
Fsetdta(&statbuf);
/* Get screen rez */
rez = Getrez();
drv_map = Drvmap();
#ifdef MWC
if((m_screen = (long *)lmalloc(
(unsigned long)((8L*1024L+32L)*(long)sizeof(long))))
== (long *)NULL)
{
Bconws("Sorry, could not allocate enough memory\r\n");
Pterm(3);
}
if((bufr = (unsigned char *)lmalloc((unsigned long)BBUFSIZ))
== (unsigned char *)NULL)
{
Bconws("Sorry, could not allocate enough memory\r\n");
Pterm(4);
}
#endif /* MWC */
#ifdef MWC
ms_ptr = (long *) ((0xffffff00L & ((long)(m_screen))) + 0x00000100L);
#else
ms_ptr = (long *) ((0xffffff00L & ((long)(&m_screen[0]))) + 0x00000100L);
#endif /* MWC */
EscSeq('e'); /* Turn on the cursor */
EscSeq('v'); /* wrap at end of line */
EscSeq('E'); /* clear screen */
SetIoBuf();
/* Txoff(); */
Rsconf((int) BAUD_DEFAULT, flowctl, ucr, rsr, tsr, scr); /* init set */
Vsync(); Vsync();
/* Txon(); */
speed = BAUD_DEFAULT;
Baudrate = BAUD_RATE;
aline_addr = aaddress();
help();
i = 0;
while (0 == 0) /* infinite loop */
{
while (Bconstat(rs232) != 0)
{
/* Char at Modem */
c = Bconin(rs232) & 0x007f;
Bconout(console, c);
/* Check the console once in a while */
/* important at High speeds */
if ((++i) & 32)
{
if (Bconstat(console) != 0)
{
conin = Bconin(console);
Bconout(rs232, (int) (conin & 0x007f));
}
i = 0;
}
}
if (Bconstat(console) != 0)
{
/* Char at Console */
conin = Bconin(console);
if ((conin & 0x00FF0000L) == 0x00610000L) /* Undo */
{
ResetIoBuf();
finish();
}
if ((conin & 0x00FF0000L) == 0x00620000L) /* Help */
help();
else
Bconout(rs232, (int) (conin & 0x007f));
}
}
}
finish()
{
#ifdef MWC
free(bufr);
free(m_screen);
#endif
Pterm0();
}
/** EOF **/